<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        .moreBig {
            position: absolute;
            top: 100px;
            left: 100px;
            width: 600px;
            height: 600px;
            background-color: orange;
        }
        .big {
            position: absolute;
            top: 100px;
            left: 100px;
            width: 400px;
            height: 400px;
            background-color: green;
        }
        .small {
            position: absolute;
            top: 100px;
            left: 100px;
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="moreBig">
        <div class="big">
            <div class="small"></div>
        </div>
    </div>
<script>
    let small = document.querySelector('.small');
    let distance = {
        left:0,
        top: 0
    };
    function findDi(obj){
        if (obj.offsetParent) {
            findDi(obj.offsetParent);
            distance.left += obj.offsetLeft;
            distance.top += obj.offsetTop;
        }
    }
    findDi(small);
    /*console.log(findDi(small));*/

    small.addEventListener('mousemove',function (e) {
        let x = e.pageX - distance.left;
        let y = e.pageY - distance.top;

        console.log('我在盒子内的坐标:' + '(' +x +','+  y + ')');
    });
    small.addEventListener('mouseout',function () {
        console.log('我出盒子了')
    });

</script>
</body>
</html>